home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / MAKEKEY1.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  5KB  |  126 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to create *)
  4. (* an encrypted registration-key file.                                *)
  5. (**********************************************************************)
  6.  
  7. program Make_FlxKey_Demo1;
  8. uses
  9.   FlxKey;
  10.  
  11. var           (* This variable is used to check for errors returned   *)
  12.               (* by CreateFlxKey routine.                             *)
  13.   ErrorCode  : word;
  14.  
  15.               (* Encryption-code strings used to create encrypted     *)
  16.               (* registration-key file.                               *)
  17.   Ecode1,
  18.   Ecode2 : st_100;
  19.  
  20.               (* This is the full path/filename of the encrypted      *)
  21.               (* registration-key file to be created.                 *)
  22.   RegKeyName : st_79;
  23.  
  24.               (* This variable is used to pass the user-data to the   *)
  25.               (* CreateFlxKey routine.                                *)
  26.   TempKeyRec : rc_Flx;
  27.  
  28.               (* Main program execution block.                        *)
  29. BEGIN
  30.               (* Clear the temporary key-record variable.             *)
  31.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  32.  
  33.               (* Assign data to temporary key-record.                 *)
  34.   with TempKeyRec do
  35.     begin
  36.               (* 20 char space is available for first-name.           *)
  37.       FirstName := 'John';
  38.  
  39.               (* 30 char space is available for last-name.            *)
  40.       LastName  := 'Smith';
  41.  
  42.               (* 30 char space is available for Address1.             *)
  43.       Address1  := '1234 AnyPlace Road,';
  44.  
  45.               (* 30 char space is available for Address2.             *)
  46.       Address2  := 'BigCity BigPlace,';
  47.  
  48.               (* 30 char space is available for Address3.             *)
  49.       Address3  := 'BigCountry, BigZip';
  50.  
  51.               (* 20 char space is available for application-name.     *)
  52.       AppName   := 'Amazing Program';
  53.  
  54.               (* Version can be assigned any valid word data.         *)
  55.       Version   := 310;
  56.  
  57.               (* Serial can be assigned any valid longint data.       *)
  58.       Serial    := 1234567890;
  59.  
  60.               (* Date can be assigned any valid "packed" date/time.   *)
  61.               (* If a value of 0 is assigned to Date, CreateFlxKey    *)
  62.               (* routine will assign the current date/time to this    *)
  63.               (* variable in "packed" date/time format. Use TP's      *)
  64.               (* standard "PackTime" and "UnPackTime" routines to     *)
  65.               (* manipulate this data.                                *)
  66.       Date      := 0;
  67.  
  68.               (* Access level can be assigned a number from 0..65,535 *)
  69.       Access    := 1234;
  70.  
  71.       MiscData  := 'You can place what ever sort of data you like' +
  72.                    #13#10 + '                within this field, ' +
  73.                    'upto 254 bytes worth.'
  74.  
  75.     end;
  76.  
  77.               (* Assign encryption-code strings used to create the    *)
  78.               (* encrypted registration-key file.                     *)
  79.   Ecode1 := 'Apple';
  80.   Ecode2 := 'Orange';
  81.  
  82.               (* Filename for the encrypted registration-key to be    *)
  83.               (* created.                                             *)
  84.   RegKeyName := 'DEMO1.KEY';
  85.  
  86.               (* Create encrypted registration-key using the data     *)
  87.               (* assigned to TempKeyRec.                              *)
  88.   CreateFlxKey(TempKeyRec, Ecode1, Ecode2, RegKeyName, ErrorCode);
  89.  
  90.               (* Move cursor down one line.                           *)
  91.   writeln;
  92.  
  93.               (* Check for errors.                                    *)
  94.   case (ErrorCode AND $FF) of
  95.      0 : writeln(' Sucessful key creation! No errors.');
  96.      1 : writeln(' Error! One or more encryption-codes is blank.');
  97.      2 : writeln(' Error! Filename for registration-key file is blank.');
  98.      3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  99.                  'buffer.');
  100.      4 : writeln(' BlocWrite error.');
  101.      5 : writeln(' BlockRead error.');
  102.      6 : writeln(' Date error. PC''s system date pre-dates ' +
  103.                  'registration-key date.');
  104.      7 : writeln(' Registration-key is corrupt.');
  105.  
  106.               (* I/O error!                                           *)
  107.     16 : begin
  108.            writeln(' I/O error = ', (ErrorCode shr 8));
  109.  
  110.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  111.               (* as there are many types of errors to check for.      *)
  112.            case (ErrorCode shr 8) of
  113.                2 : writeln(' File not found.');
  114.                3 : writeln(' Path not found.');
  115.                4 : writeln(' Too many files open.');
  116.                5 : writeln(' File access denied.');
  117.              101 : writeln(' Disk write error.');
  118.              103 : writeln(' File not open');
  119.              150 : writeln(' Disk is write-protected')
  120.            end  (* case (ErrorCode shr 8) of                          *)
  121.          end
  122.   end         (* case (ErrorCode AND $FF) of                          *)
  123. END.
  124.  
  125.  
  126.